package com.yuexi.infrastructure.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    
    private final static String CREATE_DATE = "createTime";
    private final static String UPDATE_DATE = "updateTime";

    @Override
    public void insertFill(MetaObject metaObject) {
        //创建时间
        Date now = new Date();
        strictInsertFill(metaObject, CREATE_DATE, Date.class, now);
        strictInsertFill(metaObject, UPDATE_DATE, Date.class, now);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //更新时间
        strictUpdateFill(metaObject, UPDATE_DATE, Date.class, new Date());
    }
}
